﻿using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;

public partial class LitMenu
{
    /// <summary>
    /// 打开入口场景
    /// </summary>
    [MenuItem("LitMenu/Entrance", priority = 100)]
    public static void OpenEntrance()
    {
        if (Application.isPlaying) return;
        var scene = "Assets/InApp/Entrance.unity";
        EditorSceneManager.OpenScene(scene);
    }

    /// <summary>
    /// 项目环境
    /// </summary>
    [MenuItem("LitMenu/Environment/Select", priority = 101)]
    public static void ChangeEnvironment()
    {
        var guids = AssetDatabase.FindAssets($"t:{typeof(ProjectEnvironment)}");
        if (guids == null || guids.Length <= 0)
        {
            Debug.LogError("[LitFramework] ProjectEnvironment 配置为空");
            return;
        }
        var path = AssetDatabase.GUIDToAssetPath(guids[0]);
        var env = AssetDatabase.LoadAssetAtPath<ProjectEnvironment>(path);
        Selection.activeObject = env;
    }

    /// <summary>
    /// 项目环境设置为Editor
    /// </summary>
    [MenuItem("LitMenu/Environment/SetEditor", priority = 102)]
    public static void ChangeEnvironmentEditor()
    {
        var guids = AssetDatabase.FindAssets($"t:{typeof(ProjectEnvironment)}");
        if (guids == null || guids.Length <= 0)
        {
            Debug.LogError("[LitFramework] ProjectEnvironment 配置为空");
            return;
        }
        var path = AssetDatabase.GUIDToAssetPath(guids[0]);
        var env = AssetDatabase.LoadAssetAtPath<ProjectEnvironment>(path);
        env.env = Environment.Editor;
        EditorUtility.SetDirty(env);
        AssetDatabase.SaveAssets();
    }
}
